package GUILayer;
import ControlLayer.CtrAttributeGroup;
import ModelLayer.AttributeGroup;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class GUIAttributeGroup extends javax.swing.JFrame {
    private CtrAttributeGroup ctrAttributeGroup;

    public GUIAttributeGroup() {
        initComponents();
        ctrAttributeGroup = CtrAttributeGroup.getInstance();
        loadTableContent();
    }

    private void loadTableContent() {
        ((DefaultTableModel)tblAttributeGroupList.getModel()).setRowCount(0);
        ArrayList<AttributeGroup> attributeGroupList = ctrAttributeGroup.getAttributeGroupList();
        for (AttributeGroup attributeGroup : attributeGroupList) {
            ((DefaultTableModel)tblAttributeGroupList.getModel()).addRow(
                new Object [] {
                    attributeGroup.getIDAttributeGroup(),
                    attributeGroup.getIsColorGroup(),
                    attributeGroup.getName(),
                    attributeGroup.getPublicName()
                }
            );
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrlAttributeGroupList = new javax.swing.JScrollPane();
        tblAttributeGroupList = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblAttributeGroupList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "id", "is_color_group", "name", "public_name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        scrlAttributeGroupList.setViewportView(tblAttributeGroupList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlAttributeGroupList, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlAttributeGroupList, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIAttributeGroup().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane scrlAttributeGroupList;
    private javax.swing.JTable tblAttributeGroupList;
    // End of variables declaration//GEN-END:variables

}
